package com.system.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author duanfeixiang
 * @create 2020-12-16 10:41
 */
public class CodeUtil {
    /**
     * 检查验证码是否和预期相符
     *
     * @param request
     * @return
     */
    public static boolean checkVerifyCode(HttpServletRequest request) {
        /**
         *验证码框内字符串，verifyCodeActual为login.jsp上验证码框input的name，
         *除了这个需要改换成自己的name，其他可以直接套用
         *HttpServletRequestUtil是一个工具类
         */
        String verifyCodeExpected = (String) request.getSession()
                .getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
        String verifyCodeActual = HttpServletRequesUtil.getString(request, "j_captcha");
        if (verifyCodeActual == null || !verifyCodeActual.equals(verifyCodeExpected)) {
            return false;
        }
        System.out.println("verifyCodeActual方法进来了.......");
        return true;
    }
}
